package xyz.yuzegod.megawalls.command;

import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.game.Game;
import xyz.yuzegod.megawalls.game.GamePlayer;

import java.util.ArrayList;
import java.util.List;

public class CommandSurface extends BaseCommand
{
    private List<GamePlayer> used;
    
    public CommandSurface() {
        super("surface");
        this.used = new ArrayList<GamePlayer>();
        this.setPermission("MegaWalls.default");
    }
    
    @Override
    public String getPossibleArguments() {
        return "";
    }
    
    @Override
    public int getMinimumArguments() {
        return 0;
    }
    
    @Override
    public void execute(final CommandSender sender, final String label, final String[] args) throws CommandException {
        final Game game = MegaWalls.getInstance().getGame();
        if (game == null) {
            sender.sendMessage("§c§l未获取到游戏对象,无法强制开启游戏！");
            return;
        }
        if (game.isStarted()) {
            final GamePlayer gamePlayer = GamePlayer.get(((Player)sender).getUniqueId());
            if (gamePlayer.isSpectator()) {
                return;
            }
            if (gamePlayer.getPlayerStats().getEffectStats().isSurface() && !this.used.contains(gamePlayer)) {
                final Player player = (Player)sender;
                player.teleport(gamePlayer.getGameTeam().getSpawnLocation());
                this.used.add(gamePlayer);
            }
        }
    }
    
    @Override
    public boolean isOnlyPlayerExecutable() {
        return true;
    }
}
